/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.edu.kamai.utility;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 *
 * @author Administrator
 */
public class MD5 {
    public static String Md5(String originPwd){
        StringBuffer buf = new StringBuffer("");
        try{
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(originPwd.getBytes());
            byte[] b = md.digest();
            
            for(int offset = 0;offset<b.length;offset++){
                int i = b[offset];
                if(i<0)i+=256;
                if(i<16)buf.append("0");
                buf.append(Integer.toHexString(i));
            }
            
        }catch(NoSuchAlgorithmException nsae){
            nsae.printStackTrace();
        }
        
        return buf.toString();
    }
    
    /*
    public static void main(String[] arg){
        System.out.println(MD5.Md5("b"));
    }
     * 
     */
}
